import 'package:flutter/material.dart';
import 'package:videotop/base_model.dart';
import 'package:videotop/jsonbean/login_bean.dart';
import 'package:videotop/myinfo.dart';
import 'package:videotop/widget/home.dart';

import '../util.dart';

/// created by hx
///    2021/1/23:17:32

class ChooseSexModel extends BaseModel{

  int type;
  String logid;
  String psd;
  BuildContext context;
  Util util;
  MyInfo myInfo;
  ChooseSexModel(this.type,this.logid,this.psd,this.context,this.util,this.myInfo);

  Color nochooseboy = Colors.white;
  Color nochoosegirl = Colors.white;
  Color nols = Colors.grey[400];
  int sex = 0;
  Color fontcolor = Colors.white;


  isboy(){
    sex = 1;
    nochooseboy = Color(0xffea9d53);
    nochoosegirl = Colors.white;
    nols = Colors.white;
    notifyListeners();
  }

  isgirl(){
    sex = 2;
    nochooseboy = Colors.white;
    nochoosegirl = Color(0xffea9d53);
    nols = Colors.white;
    notifyListeners();
  }

  Future<Null> regUser() async{
    util.waiting(context);
    LoginBean loginBean = await util.reg(type, logid,psd, '', sex);
    if(loginBean.status == 1){
      util.spfs.setInt('uid', loginBean.user.uid);
      util.spfs.setInt('type', type);
      util.spfs.setString('logid', logid);
      util.spfs.setString('psd', psd);
      myInfo.setMyInfo(loginBean.user);
      Navigator.pop(context);
      Navigator.pushAndRemoveUntil(
          context,
          new MaterialPageRoute(builder: (context) => new Home(reg: true,)),
              (route) => route == null);
    }else{
      Navigator.pop(context);
      util.showToast( 'registration failed');
    }
  }
}